import { BaseWindow } from "../../../../component/window/BaseWindow";
import { GLabel } from "../../../../../com/mui/controls/GLabel";
import { LayerManager } from "../../../manager/LayerManager";
import { Language } from "../../../../../extend/language/Language";
import { ObjCreate } from "../../common/ObjCreate";
import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { CopyConfig } from "../../../resource/CopyConfig";
import { Cache } from "../../../cache/Cache";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { CopySkillInfo } from "../../../resource/info/CopySkillInfo";
import { TilePanel } from "../../equipment/TilePanel";
import { SixtySkillSmeltCellRenderer } from "./SixtySkillSmeltCellRenderer";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { EventName } from "../../../mvc/EventName";
import { CopyType } from "../CopyType";
import { CopyMaterialCanvas } from "../crossAryadevaSecretCopy/CopyMaterialCanvas";
import { ItemData } from "../../../resource/info/ItemData";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { GuideArrowManager } from "../../../manager/GuideArrowManager";
import { DataEvent } from "../../../events/DataEvent";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { GuideArrow } from "../../guide/GuideArrow";
import { Vector } from "../../../../../__AS3__/vec/Vector";
//class SixtyMaterialPanel
    
    export  class SixtyMaterialPanel extends BaseWindow
    {
        constructor()
        {
            super();
            this._materialLabels = new Vector.<GLabel>();
            setSize(385, 440);
            this.layer = LayerManager.windowLayer;
            this.titleHeight = 25;
            this.title = Language.getString(60086);
            return;
        }

        protected /* override */ createChildren(): void
        {
            var loc1=null;
            var loc2=null;
            super.createChildren();
            ObjCreate.createBg(20, 38, 345, 388, this);
            loc1 = ResouceConst.getScaleBitmap("Friend_over");
            loc1.width = 385 - 40;
            loc1.height = 47;
            loc1.x = 20;
            loc1.y = 40;
            this.addChild(loc1);
            this._minimizeBtn = ObjCreate.createGButton("", 385 - 27, 7, 19, 19, this, "MinimizeButton");
            this._minimizeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onMinimizeClick);
            this._minimizeBtn.toolTipData = HTMLUtil.addColor(Language.getString(60087), "#FFFFFF");
            this._materialsConfig = CopyConfig.instance.getMaterialList(Cache.instance.copy.copyInfo.code);
            var loc3=0;
            while (loc3 < 6) 
            {
                loc2 = ObjCreate.createLabel("", 42 + loc3 % 3 * 115, 42 + Math.floor(loc3 / 3) * 22, 115, 20, flash.text.TextFormatAlign.LEFT, this, true, 16776960);
                loc2.setStyle("textFormat", new GTextFormat(FontUtil.songtiName, 14, 15707427));
                this._materialLabels.push(loc2);
                if (loc3 < this._materialsConfig.length) 
                {
                    loc2.htmlText = HTMLUtil.addColor((this._materialsConfig[loc3] as CopySkillInfo).name + " * 0", "#EFAD23");
                }
                ++loc3;
            }
            this._skillSmeltPanel = new TilePanel();
            this._skillSmeltPanel.x = 26;
            this._skillSmeltPanel.y = 94;
            this._skillSmeltPanel.selectable = false;
            this._skillSmeltPanel.setSize(334, 225);
            this._skillSmeltPanel.rowHeight = 75;
            this._skillSmeltPanel.columnWidth = 320;
            this._skillSmeltPanel.setStyle("cellRenderer", SixtySkillSmeltCellRenderer);
            addChild(this._skillSmeltPanel);
            this._descTip = ObjCreate.createGTextField("", 26, 325, 334, 100, this);
            this._descTip.multiline = true;
            this._descTip.mouseWheelEnabled = false;
            this._descTip.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._descTip.htmlText = CopyConfig.instance.getCopyDesc(Cache.instance.copy.copyInfo.code, 0);
            if (Cache.instance.clientSettingCache.isFirstCrossAryadevaSecretCopy) 
            {
                Dispatcher.addEventListener(EventName.CrossAryadevaSecretCopyRemoveGuideStepSecond, this.removeGuide);
            }
            return;
        }

        protected /* override */ createDisposedChildrenImpl(): void
        {
            super.createDisposedChildrenImpl();
            if (closeBtn) 
            {
                closeBtn.visible = false;
            }
            return;
        }

        /* internal  */onMinimizeClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.dispatchEvent(new Object /* flash.events.Event */(SixtyMaterialPanel.MATERIALPANEL_MINIMIZE));
            return;
        }

        public updateMaterials(arg1: Array<any>): void
        {
            var loc2=null;
            var loc3=0;
            var loc1=Cache.instance.copy.copyInfo.code;
            if (loc1 != CopyType.SIXTY_COPY) 
            {
                if (loc1 == CopyType.CROSS_ARYADEVA_SECRET_COPY) 
                {
                    if (this._copyMaterial == null) 
                    {
                        this._copyMaterial = new CopyMaterialCanvas(false);
                        this._copyMaterial.x = 100;
                        this._copyMaterial.y = 12;
                        this.addChild(this._copyMaterial);
                    }
                    this._copyMaterial.setMaterials(arg1);
                }
            }
            else 
            {
                loc3 = 0;
                while (loc3 < this._materialLabels.length) 
                {
                    if (loc3 < arg1.length) 
                    {
                        loc2 = arg1[loc3] as ItemData;
                        this._materialLabels[loc3].htmlText = HTMLUtil.addColor(loc2.itemInfo.item.name + " * " + loc2.itemAmount, "#EFAD23");
                    }
                    else 
                    {
                        this._materialLabels[loc3].htmlText = "";
                    }
                    ++loc3;
                }
            }
            this._skillSmeltPanel.dataProvider = new DataProvider(CopyConfig.instance.getCurCopySkillList(loc1));
            this._skillSmeltPanel.drawNow();
            return;
        }

        public addGuide(): void
        {
            this._guideArrow = GuideArrowManager.getGuideArrow(GuideArrowManager.Dir_L);
            this._guideArrow.x = 356;
            this._guideArrow.y = 135;
            this.addChild(this._guideArrow);
            return;
        }

        /* internal  */removeGuide(arg1: DataEvent): void
        {
            if (this._guideArrow && this._guideArrow.parent) 
            {
                this._guideArrow.parent.removeChild(this._guideArrow);
                this._guideArrow = null;
            }
            return;
        }

        public static /* const */MATERIALPANEL_MINIMIZE: string="技能炼化最小化";

        /* internal */ /* var */_minimizeBtn: GButton;

        /* internal */ /* var */_materialsConfig: Array<any>;

        /* internal */ /* var */_materialLabels: Vector.<GLabel>;

        /* internal */ /* var */_skillSmeltPanel: TilePanel;

        /* internal */ /* var */_descTip: GTextFiled;

        /* internal */ /* var */_copyMaterial: CopyMaterialCanvas;

        /* internal */ /* var */_guideArrow: GuideArrow;
    }
